<template>
  <div class="region-item">
    <div class="title">
      {{ region.regionLevelGroupName }}
    </div>
    <ul class="region-info-vo-list">
      <li class="region-info" v-for="item in region.regionInfoVOList" :key="item.regionId">
        <div class="region-title">
          {{ item.regionName }}
        </div>
        <div class="btn-group">
          <div>
            <el-tooltip effect="dark" content="点位管理" placement="top">
              <i class="icon iconfont icon-a-zu4891" @click="pointView(item)"/>
            </el-tooltip>
          </div>
          <div class="btn-center">
            <el-tooltip effect="dark" content="编辑区域" placement="top">
              <i class="icon iconfont icon-bianji" @click="editRegion(item)"/>
            </el-tooltip>
          </div>
          <div>
            <el-tooltip effect="dark" content="删除区域" placement="top">
              <i class="icon iconfont icon-shanchu" @click="delRegion(item)"/>
            </el-tooltip>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import {delRegionApi, regionDetailDTO, regionInfoDTO} from "@/api/region";
import {ElMessage, ElMessageBox} from "element-plus";
import {REGION_CLASSIFY} from "@/constants/mapConstants";

export interface Props {
  region: regionDetailDTO
}

const props = withDefaults(defineProps<Props>(), {})

const emit = defineEmits(['edit-region','afterSubmit', 'point-view']);

const pointView = (regionInfo: regionInfoDTO) => {
  emit('point-view', regionInfo);
}
const editRegion = (regionInfo: regionInfoDTO) => {
  emit('edit-region', regionInfo, '区域');
}
const delRegion = (regionInfo: regionInfoDTO) => {
  ElMessageBox.confirm('确认要删除所选区域吗？', '提示', {type: 'warning',})
    .then(async () => {
      let res = await delRegionApi({
        id: regionInfo.regionId,
        regionClassify: REGION_CLASSIFY['区域'].VALUE
      })
      if (res.data.code == 0) {
        ElMessage.success('删除成功')
        emit('afterSubmit')
      }
    })
}


</script>

<style lang="scss" scoped>
.region-item {
  padding-bottom: 20px;
  .title {
    font-weight: 700;
  }
  .region-info-vo-list {
    margin-top: 15px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .region-info {
      width: 250px;
      height: 110px;
      box-shadow: 0 0 10px 0 #e6e9ef;
      background: #fff;
      border-radius: 5px;
      position: relative;
      overflow: hidden;
      margin-right: 20px;
      margin-bottom: 20px;
      transition: all 0.2s;
      &:hover {
        box-shadow: 0px 0px 10px 10px #e6e9ef;
        transform: translateY(-1px);
      }
      .region-title {
        font-weight: 800;
        word-wrap: break-word;
        height: 70px;
        padding: 10px 20px;
      }
      .btn-group {
        border-top: 1px solid #E9ECF7;
        padding: 10px;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        width: 100%;
        .btn-center {
          width: 150px;
        }
      }
    }
  }
}
</style>